#!/usr/bin/env ruby

unless (ARGV[1]) then
  puts "usage :\n #{$0} epic.solb inria.solb"
  exit 1
end

system("transmesh #{ARGV[0]} ref_epic.sol")

lines = IO.readlines('ref_epic.sol')

File.open('ref_ref.sol','w') do |f|
  f.puts "MeshVersionFormatted 2"
  f.puts
  f.puts "Dimension 2"
  f.puts
  f.puts "SolAtVertices"
  nnode = lines[5].to_i
  printf("%d nodes\n",nnode)
  f.puts nnode
  f.puts "1 3"
  nnode.times do |i|
    line = lines[i+7]
    col = line.split(/ /)
    # Boeing m11 m12 m13 m22 m23 m33
    # INRIA  m11 m12 m22 m13 m23 m33
    m11 = col[0].to_f
    m12 = col[1].to_f
    m22 = col[3].to_f
    f.printf( " %.18e %.18e %.18e\n",
              m11, m12, m22 )
  end
  f.puts
  f.puts "End"
end

system("transmesh ref_ref.sol #{ARGV[1]}")
